﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<Langben.DAL.SysOperation>" %>

<!DOCTYPE html>
<html>
<head id="Head1">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>操作</title>
    <script src="<%: Url.Content("~/Scripts/jquery.min.js") %>" type="text/javascript"></script>
    <script src="<%: Url.Content("~/Scripts/JScriptIndex.js") %>" type="text/javascript"></script>
    <script src="<%: Url.Content("~/Res/easyui/jquery.easyui.min.js") %>" type="text/javascript"></script>
    <script src="<%: Url.Content("~/Res/easyui/locale/easyui-lang-zh_CN.js") %>" type="text/javascript"></script>
    <link href="<%: Url.Content("~/Res/easyui/themes/default/easyui.css") %>" rel="stylesheet"
        type="text/css" />
    <link href="<%: Url.Content("~/Res/easyui/themes/icon.css") %>" rel="stylesheet"
        type="text/css" />
    <link href="<%: Url.Content("~/Content/StyleSheet.css") %>" rel="stylesheet" type="text/css" />
    <script type="text/javascript">

        $(function () {
            $('#myTree').tree({
                
                url: '../PersonTree/GetTree?isgeren=1',
                checkbox: true,
                lines: true
            });
            $('#sendmessage').click(function () {
                var content = $('#messagecontent').val();
                if (content == "") {
                    alert("请输入短信内容。");
                    return;
                }
                var nodes = $('#myTree').tree('getChecked');
                var geren = '';
                var gerencount = 0;
                var xitong = '';
                var xitongcount = 0;
                for (var i = 0; i < nodes.length; i++) {
                    //说明是有留下手机号的。
                    if (nodes[i].iconCls == "icon-ok") {
                        //说明是个人通讯录的。attributes=1就是个人的。
                        if (nodes[i].attributes == "1") {
                            if (geren != '') {
                                geren += ',';
                            }
                            geren += nodes[i].id;
                            gerencount++;
                        }
                            //系统里面的
                        else {
                            if (xitong != '') {
                                xitong += ',';
                            }
                            xitong += nodes[i].id;
                            xitongcount++;
                        }
                    }
                }
                if (gerencount == 0 && xitongcount == 0) {
                    alert("请至少选择一个有手机号码的用户。");
                    return;
                }
                $.ajax({
                    url: "../Message/AjaxSendMessage",
                    data: { geren: geren, xitong: xitong, content: content },
                    dataType: 'text',
                    success: function (data) {
                        alert(data);
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        alert(XMLHttpRequest.status);
                        alert(XMLHttpRequest.readyState);
                        alert(textStatus);
                    }
                });
            });
        });

    </script>
</head>
<body class="easyui-layout">
    <div region="west" split="true" title="人员选择" style="width: 180px;">
        <ul id="myTree">
        </ul>
    </div>
    <div id="content" region="center" fit="true" title="短信内容">
        <textarea id="messagecontent"    rows="5" ></textarea>
        <br />
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" id="sendmessage">发送</a>
    </div>

    <input id="hidtreeid" type="hidden" />

</body>
</html>

